---
title: How to program an SOIC-8 or SOIC-16 SPI flash chip using CH341a USB programmer
...

This document exists as a guide for reading from or writing to an SPI flash chip using CH341a USB programmer using the [flashrom](http://flashrom.org/Flashrom) software. This hardware setup is more convenient than the alternatives, since it doesn't require an external power source or a Raspberry Pi.


## Prerequisites
* **For SOIC-8 chips:** CH341a USB Programmer + SOIC-8 clip bundle 
* **For SOIC-16 chips:** CH341a, 6 female-to-female jumper wires and a standalone SOIC-16 clip
* Philips head screwdriver
* Second computer with a USB port running Linux or macOS

## Extracting the MAC address from the stock firmware
Use [this tutorial](https://libreboot.org/docs/hardware/mac_address.html) to determine the MAC address of the stock BIOS on your motherboard

## Determining the chip type

First of all, we need to determine the type of the SPI chip installed on the machine. The most popular one on modern machines is SOIC-8; Lenovo and IBM Thinkpads manufactured before 2009 often come with SOIC-16 chips. Disassemble your computer according to the Hardware Maintenance Manual and locate the chip on the motherboard. 

**SOIC-8 chip**:

![SOIC-8 chip](images/ch341a/soic8.jpg)

**SOIC-16 chip**:

![SOIC-16 chip](images/ch341a/soic16.jpg)

## SOIC-8 chip
If your machine is equipped with an SOIC-8 SPI chip, you can buy a CH341a bundle that already comes with an SPI clip – it plugs directly into the ZIF socket on the programmer and doesn't require manually connecting the individual wires to the programmer.

![SOIC-8 chip](images/ch341a/ch341a-top.png)

Afer connecting the clip to the programmer you need to fit the clip on the chip. The SPI chip on your machine will have a small dimple on one of the corners:

![Dimple](images/ch341a/dimple.png)

Align the red wire on the clip to that dimple and mount the clip on the chip as shown:


![Clip on the chip](images/ch341a/clip_on_the_chip_side.jpg)

## SOIC-16 chip
In the case of SOIC-16 chips, it is not advised to use a ZIF socket clip: the length of the wires will most likely cause an interference that will **prevent you from getting a reliable read from the chip**. In this case it's recommended to use a dedicated Pomona (or similar) SPI clip and connect it directly to the pins on the side of the programmer using female-to-female jumper wires.

**The connection diagram for CH341a and SOIC-16 chip**

![SOIC-16 connectoin diagram](images/ch341a/diagram.png)


## Software preparations

Install the `flashrom` package from your system's repositories. On macOS you can install flashrom using Homebrew:

```
brew install flashrom
```

Connect the programmer to the USB port of your computer and read the current firmware from the chip:
```
flashrom -p ch341a_spi -r bios.rom
```
Depending on the distribution, you might need root privileges to communicate with the programmer

Note down the ROM size:
```
Found Winbond flash chip "W25Q32.V" (4096 kB, SPI).
```
After the read is finished, read from the chip again using a different file name this time:
```
flashrom -p ch341a_spi -r bios2.rom
```
Compare two files using `diff` command. If it says "binary files bios1.rom and bios2.rom are different", disconnect the USB programmer from the computer, reseat the clip on the chip and try again. 

**Only proceed further if the `diff` output is empty**

Save one of the files to a secure place and keep it handy – this is your backup route if something goes wrong during the flashing procedure.


## Flashing Libreboot firmware

Download the right Libreboot firmware for your computer: [https://libreboot.org/download.html](https://libreboot.org/download.html) 

Pay attention to the chip size and bootloader in the filename. E.g. "libreboot_r20160907_**grub**\_x200\_**8mb**.tar.xz"

After you've downloaded the ROM, unpack it and flash the version that corresponds to the keyboard layout on your device:
```
tar xvf libreboot_r20160907_grub_x200_4mb.tar.xz
cd libreboot_r20160907_grub_x200_4mb
flashrom -p ch341a_spi -w x200_4mb_usqwerty_txtmode.rom
```
Finally, disconnect the USB programmer from the second computer, detach the SPI clip from the chip and assemble the computer.
